package com.zhang.hadoop.netty.netty.inboundhandlerandoutboundhandler;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

/**
 * @author: zhang yufei
 * @createTime:2022/3/6 10:38
 * @description:
 */
public class MyByteToLongDecoder extends ByteToMessageDecoder {

    /**
     *
     * @param channelHandlerContext 上下文
     * @param byteBuf 入站的ByteBuf
     * @param list 集合,将解码后的数据传递个下一个handler
     * @throws Exception
     */
    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
        System.out.println("MyByteToLongDecoder 被调用");
        //因为long 8个字节
        if(byteBuf.readableBytes()>=8){
            list.add(byteBuf.readLong());
        }
    }
}
